﻿<?php
ob_start();
include 'connect/connect.php';
include 'class/class.phieuthu.php';
?>
<form method="POST" action="#">
  <p><select size="1" name="timkiem">
      <option value="1">Phi&#7871;u thu tháng này</option>
      <option value="2">Tr&#7841;ng thái: Hoàn thành</option>
      <option value="3">Trạng thái: Khách hàng đã đặt cọc</option>
      <option value="4">Tr&#7841;ng thái:Khách hàng ti&#7873;m n&#259;ng</option>
      <option value="8">Tr&#7841;ng thái:Hủy</option>
      <option value="5">Khóa: t&#7841;i nhà</option>
      <option value="6">Khóa: t&#7853;p trung</option>
      <option value="7">Khóa: H&#7885;c tr&#7921;c tuy&#7871;n</option>
    </select><input type="submit" value="Tìm ki&#7871;m" name="B1"></p>
</form>
<?php
$phieuthu = new phieuthu;
$timkiem=0;
if(isset($_POST['timkiem']))
$timkiem = $_POST['timkiem'];
if ($timkiem == 1) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu where f_email is not null order by f_ngaytao")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Ngày tạo</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  $list1 = explode("-", date('d-m-20y'));

  while ($row = mysql_fetch_array($result)) {
    $ngaytao = $row['f_ngaytao'];
    $list2 = explode("-", $ngaytao);
    if ($list1[1] == $list2[1] && $list1[2] == $list2[2]) {
      echo "<tr>";
      echo "<td>" . $row['f_maphieu'] . "</td>";
      echo "<td>" . $row['f_hovaten'] . "</td>";
      echo "<td>" . $row['f_email'] . "</td>";
      echo "<td>" . $row['f_ngaytao'] . "</td>";
      echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
      echo "</tr>";
    }
  }
}
else if ($timkiem == 2) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_trangthai = 1 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Trạng thái</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->trang_thai($row['f_trangthai']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 3) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_trangthai = 2 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Trạng thái</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->trang_thai($row['f_trangthai']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 4) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_trangthai = 4 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Trạng thái</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->trang_thai($row['f_trangthai']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 5) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_trangthai = 3 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Trạng thái</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->trang_thai($row['f_trangthai']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 6) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_khoa=1 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Khóa</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->khoa($row['f_khoa']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 7) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_khoa=2 and f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Khóa</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->khoa($row['f_khoa']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
else if ($timkiem == 8) {
  $result = mysql_query("SELECT * FROM tbl_thuphieu WHERE f_khoa=3 f_email is not null order by f_maphieu")
      or die(mysql_error());
  echo "<table border='1' width='900'>";
  echo '<td width="30" bgcolor="#D6E0D8">ID</td>
			<td width="100" bgcolor="#D6E0D8">Họ và tên</td>
			<td width="100" bgcolor="#D6E0D8">Email</td>
			<td width="100" bgcolor="#D6E0D8">Trạng thái</td>
			<td width="100" bgcolor="#D6E0D8">Edit</td>
			';
  while ($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['f_maphieu'] . "</td>";
    echo "<td>" . $row['f_hovaten'] . "</td>";
    echo "<td>" . $row['f_email'] . "</td>";
    echo "<td>" . $phieuthu->khoa($row['f_khoa']) . "</td>";
    echo '<td bgcolor="#D6E0D8"> <a href="edit.php?stt=' . $row['f_maphieu'] . '">Edit</a></td>';
    echo "</tr>";
  }
}
echo "</table>";
?>